﻿using System;
using System.Web;
using System.Web.UI;
using System.Linq;
using Models;


public partial class StoreAdd : AdminBase
{
    public int _Id = 0;

    protected void Page_Load(object sender, EventArgs e)
    {

        Response.CacheControl = "no-cache";
        if (!string.IsNullOrEmpty(Request.Params["ID"]))
        {
            _Id = int.Parse(HttpContext.Current.Request.QueryString["ID"]);

        }

        if (!Page.IsPostBack)
        {

            if (_Id != 0)
            {
                ShowInfo(_Id);
            }

        }
    }

    private void ShowInfo(int _id)
    {

        Entities mydb = new Entities();
        {

            Photo_Store _lt = mydb.Photo_Store.First(p => p.SID == _id);
            txtSname.Text = _lt.Sname;
            txtSstime.Text = _lt.Sstime.ToString();
            txtSetime.Text = _lt.Setime.ToString();
            txtStel.Text = _lt.Stel;
            txtImgUrl.Text = _lt.Simg;
            txtSaddresse.Text = _lt.Saddress;
            txtSintroduce.Text = _lt.Sintroduce;
        }
    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        Entities mydb = new Entities();
        {
            Photo_Store Lt = new Photo_Store();
            if (_Id != 0)
                Lt = mydb.Photo_Store.First(p => p.SID == _Id);

            Lt.Sname = txtSname.Text.Trim();
            Lt.Sstime = DateTime.Parse(txtSstime.Text.ToString());
            Lt.Setime = DateTime.Parse(txtSetime.Text.ToString());
            Lt.Stel = txtStel.Text.Trim();
            Lt.Simg = txtImgUrl.Text.Trim();
            Lt.Saddress = txtSaddresse.Text.Trim();
            Lt.Sintroduce = txtSintroduce.Text.Trim();


            if (_Id == 0)
            {
                mydb.Photo_Store.Add(Lt);
                mydb.SaveChanges();
                Response.Write("<script> var Close=1;</script>");
                // JscriptPrint("自定义标签添加成功啦！", "list.aspx", "Success");
            }
            else
            {
                mydb.SaveChanges();
                Response.Write("<script> var Close=1;</script>");

                // JscriptPrint("自定义标签修改成功啦！", "list.aspx", "Success");
            }
        }
    }
}

